package com.woniu.cms.goods.core.controller;


import com.woniu.cms.goods.core.dto.ReturnDto;
import com.woniu.cms.goods.core.entity.GoodsOutbill;
import com.woniu.cms.goods.core.entity.GoodsOutbillMaterial;
import com.woniu.cms.goods.core.entity.GoodsReturn;
import com.woniu.cms.goods.core.entity.GoodsReturnMaterial;
import com.woniu.cms.goods.core.service.IGoodsReturnService;
import com.woniu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 退料单表 前端控制器
 * </p>
 *
 * @author romantic sheep
 * @since 2022-09-19
 */
@Api(tags = "退料单")
@RestController
@RequestMapping("/goods-return")
public class GoodsReturnController {

    @Autowired
    private IGoodsReturnService returnService;
    /*
     * 新增退料单
     * @goodsReturn，退料单主表信息
     * @list，退料单材料明细页材料列表
     * */
    @ApiOperation("新增退料单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "returnDto",value = "退料单主表信息,退料单材料明细页材料列表")
    })
    @PostMapping("insert")
    public Result addReturn(@RequestBody ReturnDto returnDto){
        GoodsReturn goodsReturn = returnDto.getGoodsReturn();
        List<GoodsReturnMaterial> list = returnDto.getList();
        Result result=returnService.addReturn(goodsReturn,list);
        return result;
    }
    /*
     * 删除退料单
     * @id，退料单主表id
     * @status，提交状态（0-未提交，1-已提交（审批中），2-审批通过，3-已驳回）
     * */
    @ApiOperation("删除退料单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "退料单主表id"),
            @ApiImplicitParam(name = "status",value = "提交状态（0-未提交，1-已提交（审批中），2-审批通过，3-已驳回）")
    })
    @DeleteMapping("delete")
    public Result deleteReturn(Integer id,Integer status){
        Result result=returnService.deleteReturn(id,status);
        return result;
    }
    /*
     * 修改退料单
     * @goodsReturn，退料单主表信息
     * @list，退料单材料明细页材料列表
     * */
    @ApiOperation("修改退料单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "returnDto",value = "退料单主表信息,退料单材料明细页材料列表")
    })
    @PutMapping("update")
    public Result updateReturn(@RequestBody ReturnDto returnDto){
        GoodsReturn goodsReturn = returnDto.getGoodsReturn();
        List<GoodsReturnMaterial> list = returnDto.getList();
        Result result=returnService.updateReturn(goodsReturn,list);
        return result;
    }
    /*
     * 提交退料单
     * @goodsReturn，退料单主表信息
     * @list，退料单材料明细页材料列表
     * */
    @ApiOperation("提交退料单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "returnDto",value = "退料单主表信息,退料单材料明细页材料列表")
    })
    @PutMapping("commit")
    public Result commitReturn(@RequestBody ReturnDto returnDto){
        GoodsReturn goodsReturn = returnDto.getGoodsReturn();
        List<GoodsReturnMaterial> list = returnDto.getList();
        Result result=returnService.commitReturn(goodsReturn,list);
        return result;
    }
}

